﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Security;

namespace CommonTagTime
{
    public class clsCookies
    {
        /// <summary>
        /// Create an cookie
        /// </summary>
        public static void RegisterCookies(string strCookieName, string strValue)
        {
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, strCookieName, DateTime.Now,
                    DateTime.Now.AddDays(30), false, strCookieName, FormsAuthentication.FormsCookiePath);
            string strEnTicket = FormsAuthentication.Encrypt(ticket);
            HttpContext.Current.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, strEnTicket));

            HttpCookie cookieName = new HttpCookie(strCookieName);
            cookieName.Value = strValue;
            cookieName.Expires = DateTime.Now.AddDays(30);
            HttpContext.Current.Response.Cookies.Add(cookieName);

        }//end function

        //-----------------------------------------------------
        /// <summary>
        /// Delete an cookie
        /// </summary>
        public static void DestroyCookies(string strCookieName)
        {
            HttpContext.Current.Request.Cookies[strCookieName].Expires = DateTime.Now.AddDays(-30);
        }
    }
}
